Code coverage report for src/browser/url.js

Statements: 47.92% (23 / 48)      Branches: 31.82% (7 / 22)      Functions: 100% (1 / 1)      Lines: 47.92% (23 / 48)      Ignored: none     

All files » src/browser/ » url.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80        27             27 27       27     27 27         27 27                                                   27 27 27 27     27     27 27 27           27 27 27 27 27   27     1  
// See https://nodejs.org/docs/latest/api/url.html
function parse(url) {
  var result = {
    protocol: null, auth: null, host: null, path: null,
    hash: null, href: url, hostname: null, port: null,
    pathname: null, search: null, query: null
  };
 
  var i, last;
  i = url.indexOf('//');
  if (i !== -1) {
    result.protocol = url.substring(0,i);
  I  last = i+2;
  } else {
    last = 0;
  }
  
  i = url.indexOf('@', last);
  if (i !== -1) {
    result.auth = url.substring(last, i);
  I  last = i+1;
  }

  i = url.indexOf('/', last);
  if (i === -1) {
    i = url.indexOf('?', last);
  I  if (i === -1) {
      i = url.indexOf('#', last);
      if (i === -1) {
        result.host = url.substring(last);
      } else {
        result.host = url.substring(last, i);
        result.hash = url.substring(i);
      }
      result.hostname = result.host.split(':')[0];
      result.port = result.host.split(':')[1];
      if (result.port) {
        result.port = parseInt(result.port, 10);
      }
      return result;
    } else {
      result.host = url.substring(last, i);
      result.hostname = result.host.split(':')[0];
      result.port = result.host.split(':')[1];
      if (result.port) {
        result.port = parseInt(result.port, 10);
      }
      last = i;
    }
  } else {
    result.host = url.substring(last, i);
    result.hostname = result.host.split(':')[0];
    result.port = result.host.split(':')[1];
    if (result.port) {
      result.port = parseInt(result.port, 10);
    I}
    last = i;
  }
 
  i = url.indexOf('#', last);
  if (i === -1) {
    result.path = url.substring(last);
  E} else {
    result.path = url.substring(last, i);
    result.hash = url.substring(i);
  }

  if (result.path) {
    var pathParts = result.path.split('?');
  E  result.pathname = pathParts[0];
    result.query = pathParts[1];
    result.search = result.query ? '?' + result.query : null;
  }
  return result;
}
 
module.exports = {
  parse: parse
};